package vn.fsoft.gst.dao;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import vn.fsoft.gst.domain.Contact;

/**
 * 
 * @author Tung
 *
 */

@Repository
public class ContactDAOImp implements ContactDAO{
	
	@Autowired
	private SessionFactory sessionFactory;
	
	@SuppressWarnings("unchecked")
	@Transactional
    public List<Contact> getListContact() {
		List<Contact> listContact = null;
		
        listContact = sessionFactory.getCurrentSession().createQuery("from Contact").list();  
        
        return listContact;
    }
	
	@Transactional
	public Contact getContactById(int id){
		Contact contact = null;
		
		contact = (Contact) sessionFactory.getCurrentSession().get(Contact.class,id);
		
		return contact;
	}
	@Transactional
	public int addContact(Contact contact) {
		return (Integer) sessionFactory.getCurrentSession().save(contact);
	}
}
